package org.zxp.javacheck.enumtest;

import org.junit.Test;

import java.awt.*;
import java.util.stream.Stream;

/**
 * @program: effectiveJava
 * @description: 枚举测试类
 * @author: X-Pacific zhang
 * @create: 2019-08-19 13:47
 **/
public class EnumTest {
    @Test
    public void test1(){
        Color1 color1 = Color1.RED;
        System.out.println(color1);//输出RED

//        Stream.of(Color1.values()).forEach(o->System.out.println(o));//顺序输出

        Color1 color2 =  Color1.valueOf("YELLOW");
        System.out.println(color2);//输出YELLOW

        System.out.println(color1.compareTo(color2));//-3 小于0 color2大
        System.out.println(color1.compareTo(color1));//0

        System.out.println(color2.ordinal());//3 输出顺序
        System.out.println(color2.name());//YELLOW


        Color1 color3 = Color1.BLANK;

        switch (color3){
            case RED:
                System.out.println("红色");break;
            case GREEN:
                System.out.println("绿色");break;
            case BLANK:
                System.out.println("黑色");break;
            case YELLOW:
                System.out.println("黄色");break;
        }
    }


    @Test
    public void test2(){
        Color2 color2 = Color2.GREEN;
        System.out.println(color2);//6_绿色 覆盖了toString
        System.out.println(color2.ordinal());//1 输出顺序
        System.out.println(color2.name());//GREEN
        System.out.println(color2.getName());//绿色
        System.out.println(color2.getIndex());//6
    }
}
